/*
 * Eugen Stoian <stoian.e@gmail.com> 2010
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef VARIABLENODE_H
#define VARIABLENODE_H

#include <ExpressionTreeNode.h>

class VariableNode : public ExpressionTreeNode
{
public:
    VariableNode(const QString& info, int pos, const Real* var = 0);

    virtual ~VariableNode(){}

    virtual ExpressionTreeNode* copy() const ;

    virtual Real eval() const;

    virtual SmartPtr<ExpressionTreeNode> derive(const QString& varName) const;

    inline virtual QString info() const {
        return _info;
    }

    /**
     *\fn bool isVariabile() const
     *\brief Returns true
     * Reimplemented from ExpressionTreeNode
     *
     */
    inline virtual bool isVariable() const {
        return true;
    }

    virtual QString toPrefixString() const;

    virtual QString toPostfixString() const;

    virtual QString toInfixString() const;

    inline virtual int precedence() const {
        return DEFAULT_PRECEDENCE;
    }
    virtual SmartPtr<ExpressionTreeNode> firstLevelSimplification() const;

    virtual void bind(const QString& varName,const Real * var) const{
        if(_info==varName)
            _variable = var;
    }

    virtual void bind(int varPos,const Real * var) const{
        if(_pos==varPos)
            _variable = var;
    }

    virtual ExpressionTreeNode* replace(const QString& varName, ExpressionTreeNode* tree) const;

    virtual ExpressionTreeNode* replace(int varPos, ExpressionTreeNode* tree) const;

    virtual void resetMarker() const{
    }

protected:
    mutable const Real * _variable;
    QString _info;
    int _pos;
};

#endif // VARIABLENODE_H
